Skip to content

feat(moshi): add local Moshi speech-to-speech adapter - #52

Merged
TudorAndrei merged 3 commits into
mainfrom
feat/moshi-adapter
Nov 6, 2026
Merged

TudorAndrei merged 3 commits into
mainfrom
feat/moshi-adapter

Conversation

@TudorAndrei

@TudorAndrei TudorAndrei commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds AudioFlow.Adapters.Moshi, a Session speech_to_speech adapter for a local Kyutai Moshi server. It is the smallest local open speech-to-speech model: 7B, 4-bit MLX, approximately 5 GB of weights. It runs on an Apple Silicon laptop.

  • Membrane first: Opus coding uses membrane_opus_plugin. Ogg pages use membrane_ogg_plugin (Page, Parser, Opus headers). There is no custom codec or container code.
  • Protocol: binary WebSocket messages with a one-byte kind (0 handshake, 1 Ogg Opus 24 kHz, 2 text). The adapter sends one Ogg page for each 80 ms frame. Membrane.Ogg.Muxer holds packets until a page has 255 segments (approximately 5 s), so the adapter builds pages directly.
  • Turn model: the adapter sends the input, then sends silence paced by the frames that it receives (not by the wall clock). It drops the output for the input period. The reply ends after :end_silence_ms (1,600) without text, or fails with :no_reply after :max_reply_ms (20,000).
  • Socket: Providers.Socket.run/7 accepts a frame decoder. The default is the old JSON decoder, so OpenAI Realtime and Gemini Live do not change.

Limits

  • The Opus Native and Ogg Page/Parser modules are internal to the plugins. The versions are pinned (~> 0.21.0, ~> 0.5.2).
  • The server accepts one connection at a time, and the model context continues across turns.
  • Moshi speaks English only and does not transcribe the user (no :transcript event).

Verification

  • AUDIOFLOW_MEDIA=1 mix test: 238 passed. Core mix test: 215 passed. credo --strict, dialyzer, mix format, rumdl: clean.
  • Live test against moshi_mlx.local_web (-q 4, M5, 24 GB): AUDIOFLOW_MEDIA=1 AUDIOFLOW_HTTP_MODEL_TESTS=1 AUDIOFLOW_MOSHI_PCM=question.s16le mix test test/moshi_test.exs passed. Session turns gave correct spoken answers. The first reply audio came 2.1–3.0 s after submit for a 3.2 s question. The first turn after server start took approximately 13 s (MLX warm-up).
  • Note: in a sandbox where TMPDIR is a symlinked /var/folders/... path, 15 recording tests fail with :unsafe_path. This is not related to this change. They pass with a non-symlinked TMPDIR.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Socket.run/7 takes a decoder that maps each text or binary frame to a
handler event. The default still accepts JSON objects only, so the
OpenAI Realtime and Gemini Live adapters do not change.
AudioFlow.Adapters.Moshi runs one committed 24 kHz turn against a local
Kyutai Moshi server (moshi_mlx.local_web) for Session speech_to_speech.
Ogg Opus framing and coding use membrane_ogg_plugin and
membrane_opus_plugin. The adapter sends one Ogg page per 80 ms frame,
paces silence by received output, drops output for the input period and
ends the reply after a silence without text tokens.
@TudorAndrei
TudorAndrei merged commit 93d7b91 into main Nov 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant